<?php 
include("../../../cfg/cfg.inc.php");
include "../../../include/functions.inc.php";

$cycles = $db->query_select("cllg_college_cycle");

function getTypeaheadData($db,$select,$table){
        $as = "DATA";
        $sqlData = sprintf("SELECT %s AS %s FROM %s",$select,$as,$table);
        $data = $db->queryToArray($sqlData);
        $string = "";

        foreach($data as $d){
            $string = isEmpty($string) ? $string : "$string,";
            $string.= '"'.$d[$as].'"';
        }
        $typeahead = "[". $string ."]";
        return $typeahead;
    }
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Certificación de Cursos</title>
        <link rel="stylesheet" href="../../../bootstrap/css/bootstrap.css" type="text/css" />
        <link rel="stylesheet" href="../../../js/ui/jquery.ui.min.css" type="text/css" />
        <script src="../../../js/jquery.js"></script>
        <script src="../../../bootstrap/js/bootstrap.js"></script>
        <script src="../../../js/jquery.ui.min.js"></script>
        <script type="text/javascript">
            function getDiplomados(){
                $.ajax({
                    type: "POST",
                    data: $("#reportform").serialize(),
                    url: "data.php?op=getDiplo",
                    success: function(data){
                        $("#diplomados").html(data);
                    } 
                })
            }
            
            function getCert(id){
                $.ajax({
                    type: "POST",
                    data: $("#reportform").serialize(),
                    url: "certificacion.php?id=" + id,
                    success: function(data){
                        $("#certificacion").html(data);
                    } 
                })
            }
            
            function getName(){
                $.ajax({
                    type: "POST",
                    data: $("#reportform").serialize(),
                    url: "data.php?op=getName",
                    success: function(data){
                        $("#name").html(data);
                    } 
                })
            }
        </script>
        <style media="print">
            .noPrint{
                display: none;
            }
            .printable{
                display: block !important;
                padding-left: 0px;
            }
        </style>
    </head>
    <body>
        <div id="tabs" class="noPrint">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a href="#">Certificación de Cursos</a>
                </li>
            </ul>
        </div>
        <div id="tab-cont">
            <form id="reportform">
                <table class="noPrint" border="0" width="100%">
                    <tr>
                        <th colspan="2">
                            <legend>Seleccione Carnet y Ciclo</legend>
                        </th>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div style="margin-left: 70%" id="newButton">
                                <a type="button" class="btn btn-info" href="index.php">Nueva Certificación</a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td width="10%">
                            <label for="carnet">CARNET</label>
                        </td>
                        <td width="90%">
                            <input style='width:250px' data-provide='typeahead' autocomplete="off" data-source='<?php echo getTypeaheadData($db,"CONCAT(ID,' - ',FIRST_NAME,' ',LAST_NAME)","cllg_student");?>' type="text" name="carnet" id="carnet">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="carnet">CICLO</label>
                        </td>
                        <td>
                            <select name="cycle" onchange="getDiplomados();">
                                <option>--Seleccione ciclo--</option>
                                <?php foreach($cycles as $cy) {?>
                                        <option value="<?php echo $cy['CODE']; ?>"><?php echo $cy['CODE']; ?></option>
                                <?php }?>
                            </select>
                        </td>
                    </tr>
                </table>
                <div class="noPrint" id="diplomados"></div>
            </form>
        </div>
        <br/>
        <div id="certificacion" class="printable" width="100%"></div>
    </body>
</html>
